
# 添加任务依赖功能, 跨任务流依赖, 添加状态触发机制 ok
# 任务流完成后，会提示任务流完成，但是没有退出任务流线程

import time
import logging
import TaskScheduler4

import taskflow_1 as tf1
import taskflow_2 as tf2

# note: each task func name need be unique

# 使用示例
if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    scheduler = TaskScheduler4.TaskScheduler()

    # 添加任务流
    scheduler.add_task_flow("flow1", 
                            [tf1.task1, tf1.task2, tf1.task3, tf1.task4], 
                            #dependencies={"task2": ["task1", "task3"]}, 
                            #dependencies={"task2": ["task1"], "task3":["task2"]}, 
                            dependencies={"task2": ["task1"], "task3":["task2"], "task4":["task3"]}, 
                            trigger_condition=tf1.trigger_condition1)

    scheduler.add_task_flow("flow2", 
                            [tf2.task5, tf2.task6, tf2.task7, tf2.task8], 
                            dependencies={"task5": ["task3"], "task7":["task5", "task8"]}, 
                            trigger_condition=tf2.trigger_condition2)

    # 启动调度器
    scheduler.set_trigger_interval_time(1)
    scheduler.start()

    # 模拟条件变为 True
    time.sleep(2)  # 模拟等待时间
    scheduler.set_ready()

    # 动态设置触发条件
    time.sleep(2)
    tf1.some_flag1 = True

    time.sleep(2)
    tf2.some_flag2 = True

    # 等待一段时间，确保任务流执行完成
    time.sleep(10)